package com.zyb.system.menu.service.impl;

import com.zyb.system.menu.domain.Menu;
import com.zyb.system.menu.mapper.MenuMapper;
import com.zyb.system.menu.service.IMenuService;
import com.zyb.base.service.impl.BaseServiceImpl;
import com.zyb.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Arvin
 * @since 2023-02-01
 */
@Service
public class MenuServiceImpl extends BaseServiceImpl<Menu> implements IMenuService {
    @Autowired
    MenuMapper menuMapper;

    @Override
    public List<Menu> getMenuTree() {
        List<Menu> menuTree = menuMapper.loadByParentId();
//        List<Menu> menus = menuMapper.loadAll();
//        for (Menu menu : menus) {
//            if(menu.getParentId() != null){
//                for (Menu parent : menus) {
//                    if(menu.getParentId() == parent.getId()){
//                        List<Menu> children = parent.getChildren();

//                        children.add(menu);
//                        break;
//                    }
//                }
//            }
//        }
//        List<Menu> menuTree = menus.stream().filter(menu -> menu.getParentId() == null).collect(Collectors.toList());
        return menuTree;
    }
}
